from typing import Optional

from sqlalchemy import Index, JSON, PrimaryKeyConstraint, String, UniqueConstraint, Uuid, text
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column
import uuid

class Base(DeclarativeBase):
    pass


class CasbinRulePath(Base):
    __tablename__ = 'casbin_rule_path'
    __table_args__ = (
        PrimaryKeyConstraint('id', 'endpoint', name='casbin_rule_path_pkey'),
        UniqueConstraint('endpoint', name='casbin_rule_path_endpoint_key'),
        Index('casbin_rule_path_id_endpoint_idx', 'id', 'endpoint', unique=True)
    )

    id: Mapped[uuid.UUID] = mapped_column(Uuid, primary_key=True, server_default=text('gen_random_uuid()'), comment='uuid')
    rule: Mapped[str] = mapped_column(String(255), comment='路由')
    methods: Mapped[dict] = mapped_column(JSON, comment='允许请求的方法')
    endpoint: Mapped[str] = mapped_column(String(255), primary_key=True, comment='所属服务端点')
    description: Mapped[Optional[str]] = mapped_column(String(255), comment='描述')
